<html><head><title>ImagePlugin.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - ImagePlugin example file
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font>
<font color="#3A3966">; Enable all the decoders than PureBasic actually supports
</font><font color="#3A3966">;
</font><font color="#3A3966">UseJPEGImageDecoder</font>()
<font color="#3A3966">UseTGAImageDecoder</font>()
<font color="#3A3966">UsePNGImageDecoder</font>()
<font color="#3A3966">UseTIFFImageDecoder</font>()

<font color="#3A3966">; Enable all the encoders than PureBasic actually supports
</font><font color="#3A3966">;
</font><font color="#3A3966">UseJPEGImageEncoder</font>()
<font color="#3A3966">UsePNGImageEncoder</font>()


<b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenWindow</font>(0, 0, 0, 250, 130, &quot;PureBasic - Image Converter&quot;, <font color="#924B72">#PB_Window_SystemMenu</font> | <font color="#924B72">#PB_Window_ScreenCentered</font>)

<font color="#3A3966">  CreateToolBar</font>(0,<font color="#3A3966"> WindowID</font>(0))
<font color="#3A3966">    ToolBarImageButton</font>(0,<font color="#3A3966"> LoadImage</font>(0, <font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/sources/Data/ToolBar/Open.png&quot;))
<font color="#3A3966">    ToolBarImageButton</font>(1,<font color="#3A3966"> LoadImage</font>(0, <font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/sources/Data/ToolBar/Save.png&quot;))
<font color="#3A3966">    DisableToolBarButton</font>(0, 1, 1)    <font color="#3A3966">; disable the save button
</font>    
<font color="#3A3966">  ImageGadget</font>(0, 0, 28,<font color="#3A3966"> WindowWidth</font>(0),<font color="#3A3966"> WindowHeight</font>(0), 0, <font color="#924B72">#PB_Image_Border</font>)
  
  <b><font color="#3A3966">Repeat</font></b>
    Event =<font color="#3A3966"> WaitWindowEvent</font>()
    
    <b><font color="#3A3966">If</font></b> Event = <font color="#924B72">#PB_Event_Menu</font>  <font color="#3A3966">; ToolBar are acting as menu
</font>    
      <b><font color="#3A3966">Select</font></b> <font color="#3A3966">EventMenu</font>()
      
        <b><font color="#3A3966">Case</font></b> 0  <font color="#3A3966">; Open
</font>        
          Filename$ =<font color="#3A3966"> OpenFileRequester</font>(&quot;Choose a picture&quot;, &quot;&quot;, &quot;All Images Formats|*.bmp;*.jpg;*.png;*.tif;*.tga&quot;, 0)
          <b><font color="#3A3966">If</font></b> Filename$
          
            <b><font color="#3A3966">If</font></b> <font color="#3A3966">LoadImage</font>(0, Filename$)
<font color="#3A3966">              SetGadgetState</font>(0,<font color="#3A3966"> ImageID</font>(0))  <font color="#3A3966">; change the picture in the gadget
</font><font color="#3A3966">              DisableToolBarButton</font>(0, 1, 0)    <font color="#3A3966">; enable the save button
</font><font color="#3A3966">              ResizeWindow</font>(0, <font color="#924B72">#PB_Ignore</font>, <font color="#924B72">#PB_Ignore</font>,<font color="#3A3966"> ImageWidth</font>(0)+4,<font color="#3A3966"> ImageHeight</font>(0)+34)
            <b><font color="#3A3966">EndIf</font></b>
          
          <b><font color="#3A3966">EndIf</font></b>
        
        <b><font color="#3A3966">Case</font></b> 1  <font color="#3A3966">; Save
</font>          
          Filename$ =<font color="#3A3966"> SaveFileRequester</font>(&quot;Save a picture&quot;,<font color="#3A3966"> Left</font>(Filename$,<font color="#3A3966"> Len</font>(Filename$)-<font color="#3A3966">Len</font>(<font color="#3A3966">GetExtensionPart</font>(Filename$))-1), &quot;BMP Format|*.bmp|JPEG Format|*.jpg|PNG Format|*.png&quot;, 0)
          <b><font color="#3A3966">If</font></b> Filename$
          
            <b><font color="#3A3966">Select</font></b> <font color="#3A3966">SelectedFilePattern</font>()
            
              <b><font color="#3A3966">Case</font></b> 0  <font color="#3A3966">; BMP
</font>                ImageFormat = <font color="#924B72">#PB_ImagePlugin_BMP</font>
                Extension$  = &quot;bmp&quot;

              <b><font color="#3A3966">Case</font></b> 1  <font color="#3A3966">; JPEG
</font>                ImageFormat = <font color="#924B72">#PB_ImagePlugin_JPEG</font>
                Extension$  = &quot;jpg&quot;
                
              <b><font color="#3A3966">Case</font></b> 2  <font color="#3A3966">; PNG
</font>                ImageFormat = <font color="#924B72">#PB_ImagePlugin_PNG</font>
                Extension$  = &quot;png&quot;

            <b><font color="#3A3966">EndSelect</font></b>
            
            <b><font color="#3A3966">If</font></b> <font color="#3A3966">LCase</font>(<font color="#3A3966">GetExtensionPart</font>(Filename$)) &lt;&gt; Extension$
              Filename$ + &quot;.&quot; + Extension$
            <b><font color="#3A3966">EndIf</font></b>
            
            <b><font color="#3A3966">If</font></b> <font color="#3A3966">SaveImage</font>(0, Filename$, ImageFormat)
<font color="#3A3966">              MessageRequester</font>(&quot;Information&quot;, &quot;Image saved successfully&quot;, 0)
            <b><font color="#3A3966">EndIf</font></b>
          
          <b><font color="#3A3966">EndIf</font></b>
      
      <b><font color="#3A3966">EndSelect</font></b>
    
    <b><font color="#3A3966">EndIf</font></b>
    
  <b><font color="#3A3966">Until</font></b> Event = <font color="#924B72">#PB_Event_CloseWindow</font>  <font color="#3A3966">; If the user has pressed on the close button
</font>  
<b><font color="#3A3966">EndIf</font></b>

<b><font color="#3A3966">End</font></b>   <font color="#3A3966">; All is automatically freed by PureBasic</font></font></pre>
</body></html>
